<?php
// handle bump and sage
if(request('id') != null)
{
	$showCaptcha = true;
	if(request('hascaptcha') != null)
	{
		$result = recaptcha_check_answer ('6Lfp7McSAAAAAFZcJah5cpmVZ9VJ4BC6MXXnmXfs', $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);	
	  	if ($result->is_valid) 
	  	{
			// bump or sage
			if(request('bump') != null)
				BoardDAO::Bump(request('id'));
			elseif (request('sage') != null)
				BoardDAO::Sage(request('id'));
			
			// hide the captcha form
			$showCaptcha = false;
			
			// close window
			?>
			<script>window.close();</script>
			<?php			
	  	} 
	  	else 
	  	{
	  		?>
	  		<span style="color: red">The captcha was incorrect. Please try again.</span><br /> 
	  		<?php
	  	}
	}
	
	if( $showCaptcha )
	{
		// show captcha form
		?>
		<form method="post">
			<?php print recaptcha_get_html('6Lfp7McSAAAAAITMGTIc3zvT4cgBlIxphYqT1lFH') ?>
			<input name="id" value="<?php print request('id') ?>" type="hidden" /> 
			<?php if( request('bump') != null ) { ?>
			<input name="bump" value="1" type="hidden" />
			<?php } elseif( request('sage') != null ) { ?>
			<input name="sage" value="1" type="hidden" />
			<?php } ?> 
			<input name="hascaptcha" value="1" type="hidden" />
			<input type="submit" />
		</form>
        <?php
	}
	exit;
}